<template>
  <div class="app-container">
    <div class="space">
      <el-form
        v-show="showSearch"
        ref="queryForm"
        :model="queryParams"
        size="small"
        :inline="true"
      >
        <el-form-item label="名称" prop="search">
          <el-input
            v-model="queryParams.search"
            placeholder="通过订单号、申请人、申请人ID进行模糊搜索"
            clearable
            style="width: 310px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="申请时间" prop="signTime">
          <el-date-picker
            v-model="queryParams.signTime"
            :default-time="['00:00:00', '23:59:59']"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            align="right"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery"
            >查询</el-button
          >
          <el-button icon="el-icon-refresh" class="delBtn" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          class="add"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col> -->
        <el-col :span="1.5">
          <el-button type="primary" @click="handleDelete"
            >批量处理 {{ ids.length || "" }}</el-button
          >
        </el-col>
        <el-button type="primary" icon="el-icon-download" @click="handleExport"
          >导出</el-button
        >
      </el-row>
    </div>
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :show-search.sync="showSearch"
        :columns="columns"
        @queryTable="getListData"
      />
    </el-row>
    <el-table
      ref="table"
      :key="tableKey"
      v-loading="loading"
      :data="roleList"
      style="margin-top: 20px"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        v-if="columns[0].visible"
        key="id"
        label="提现订单号"
        prop="id"
        :show-overflow-tooltip="true"
        width="150"
        align="left"
      />
      <el-table-column
        v-if="columns[1].visible"
        key="userName"
        label="申请人"
        prop="userName"
        :show-overflow-tooltip="true"
        width="150"
        align="left"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.userName + "-" + scope.row.userId }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="columns[2].visible"
        key="price"
        label="申请提现金额"
        prop="price"
        :show-overflow-tooltip="true"
        width="150"
        align="left"
      />
      <el-table-column
        v-if="columns[3].visible"
        key="bankAcc"
        label="开户名"
        prop="bankAcc"
        :show-overflow-tooltip="true"
        width="150"
        align="left"
      />
      <el-table-column
        v-if="columns[4].visible"
        key="bankName"
        label="银行"
        prop="bankName"
        :show-overflow-tooltip="true"
        width="150"
        align="left"
      />
      <el-table-column
        v-if="columns[5].visible"
        key="bankNo"
        label="银行卡号"
        prop="bankNo"
        :show-overflow-tooltip="true"
        width="250"
        align="left"
      />
      <el-table-column
        v-if="columns[6].visible"
        key="createTime"
        label="申请时间"
        align="left"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="left"
        fixed="right"
        class-name="fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            class="btnText"
            @click="handleDelete(scope.row)"
            v-if="editMenu"
            >处理</el-button
          >
          <!-- <el-button
            class="btnText"
            type="text"
            @click="handleDelete(scope.row)"
            >拒绝</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getListData"
    />
  </div>
</template>

<script>
import { getList, handData } from "@/api/index";
import { mapGetters } from "vuex";
export default {
  name: "Role",
  computed: {
    ...mapGetters(["menuIds"]),
    editMenu() {
      return this.menuIds.includes("1001");
    },
  },
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      columns: [
        { key: 0, label: `提现订单号`, visible: true },
        { key: 1, label: `申请人`, visible: true },
        { key: 2, label: `申请提现金额`, visible: true },
        { key: 3, label: `开户名`, visible: true },
        { key: 4, label: `银行`, visible: true },
        { key: 5, label: `银行卡号`, visible: true },
        { key: 6, label: `申请时间`, visible: true },
      ],
      tableKey: 0,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 10,
      // 角色表格数据
      roleList: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        search: "",
        signTime: "",
        status: "0", // "状态 0 申请中 1 已转账 2.已拒绝 3.已处理"
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getListData();
  },
  methods: {
    handleClick(tab, event) {
      this.resetQuery();
      this.tableKey += 1;
    },
    /** 查询角色列表 */
    getListData() {
      const data = {
        ...this.queryParams,
        startTime:
          this.queryParams.signTime &&
          new Date(this.queryParams.signTime[0]).getTime(),
        endTime:
          this.queryParams.signTime &&
          new Date(this.queryParams.signTime[1]).getTime(),
      };
      delete data.signTime;
      getList(data).then((response) => {
        this.roleList = response.data.records;
        this.total = response.data.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.$nextTick(() => {
        this.queryParams.current = 1;
        this.getListData();
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.current = 1;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      if (!row.id && !this.ids.length) {
        return this.$message.error("请选择要处理的数据");
      }
      let roleIds = row.id || this.ids;
      if (Array.isArray(roleIds)) {
        roleIds = roleIds.join(",");
      }
      this.$modal
        .confirm("是否处理该数据？")
        .then(function () {
          return handData({
            ids: roleIds,
            status: 1,
            userId: localStorage.getItem("userId"),
          });
        })
        .then(() => {
          this.getListData();
          this.$modal.msgSuccess("处理成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const data = {
        ...this.queryParams,
        startTime: this.queryParams.signTime
          ? new Date(this.queryParams.signTime[0]).getTime()
          : "",
        endTime: this.queryParams.signTime
          ? new Date(this.queryParams.signTime[1]).getTime()
          : "",
      };
      delete data.signTime;
      this.download(
        "admin/exportWithdrawalList",
        data,
        `提现申请导出${this.parseTime(new Date().getTime())}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
.btnText {
  color: #0052d9 !important;
}
.dialogForm {
  ::v-deep .el-form-item {
    margin-bottom: 10px;
  }
  ::v-deep.el-form--label-top .el-form-item__label {
    padding: 0;
  }
}
.add {
  background: #0052d9;
  color: #fff;
  border: none;
}
.delBtn {
  background: #e7e7e7;
  color: #000;
  border: none;
}
.open {
  width: 52px;
  height: 32px;
  background: #e3f9e9;
  border-radius: 3px 3px 3px 3px;
  border: 1px solid #2ba471;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 400;
  font-size: 14px;
  color: #2ba471;
}
.close {
  width: 52px;
  height: 32px;
  background: #d8d8d8;
  border-radius: 3px 3px 3px 3px;
  border: 1px solid #767676;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 400;
  font-size: 14px;
  color: #767676;
}
.statusBox {
  width: 100%;
  display: flex;
  justify-content: center;
}
.img {
  width: 38px;
  height: 38px;
}
</style>
